REM $INCLUDE: 'QB.BI'
DIM regx AS RegTypeX
CLS

regx.ax = &HB101
CALL INTERRUPTX(&H1A, regx, regx)
IF regx.flags AND 1 THEN
PRINT "PIC BIOS NOT PRESENT"
GOTO progend
END IF
PRINT "FOUND PCI BIOS"

'PRINT "CL:"; HEX$(regx.cx); "", "BX: "; HEX$(regx.bx), "AX: "; HEX$(regx.ax), "DX: "; HEX$(regx.dx)

regx.ax = &HB102
regx.cx = &H9050
regx.dx = &H10B5
regx.si = 0

CALL INTERRUPTX(&H1A, regx, regx)

IF regx.ax <> 2 THEN
PRINT "DID NOT FIND PLX PCI9050"
GOTO progend
END IF
PRINT "FOUND PLX 9050 with PLX VENDOR ID"
'PRINT "CL:"; HEX$(regx.cx), "FLAGS: "; HEX$(regx.flags), "BX: "; HEX$(regx.bx), "AX: "; HEX$(regx.ax), "DX: "; HEX$(regx.dx)
busdevnum% = regx.bx

regx.ax = &HB109
regx.di = &H2E
regx.cx = 0
regx.bx = busdevnum%
CALL INTERRUPTX(&H1A, regx, regx)
IF regx.cx = &H2496 THEN
		PRINT "FOUND RAPID CONTROLS PCI-4 LOCATED ";

	   ELSE
		PRINT "FOUND UNKNOWN PLX 9050"
			GOTO progend
	   END IF
	   regx.ax = &HB109
	   regx.di = &H18
	   regx.cx = 0
	   regx.bx = busdevnum%
	   CALL INTERRUPTX(&H1A, regx, regx)

	   'PRINT "CX:"; HEX$(regx.cx), "FLAGS: "; HEX$(regx.flags), "BX: "; HEX$(regx.bx), "AX: "; HEX$(regx.ax), "DX: "; HEX$(regx.dx)
	   IF regx.cx AND 1 THEN
		PRINT "IN I/O SPACE AT ";
	   ELSE
		PRINT "IN MEMORY SPACE AT:";
	   END IF
	   baseaddr% = regx.cx AND &HFFFE
	   PRINT HEX$(baseaddr%); "H"
	   'PRINT b%, "AX: "; HEX$(regx.ax), "CX: "; HEX$(regx.cx)
	   'NEXT b%
	   LOCATE 5, 10
	   PRINT "INTERROGATING ALL CHANNELS WITH 16 RECIRCS"
	   PRINT "         Press Q to Quit ,  C to clear max min"
	   LOCATE 8, 10
	   PRINT , "POSN", "MAX", "MIN", "STATUS"
	   PRINT "--------+-------------+-------------+------------+-----------"
	   FOR b% = 1 TO 4
		max(b%) = 0
		min(b%) = &HFFFFFF
		pwm%(b% - 1) = 0
		status%(b% - 1) = 0
		LOCATE 9 + b%, 1
		PRINT "CH"; b%; ":"
	   NEXT b%
	   ky$ = ""
WHILE ky$ <> "Q"
	ky$ = UCASE$(INKEY$)
	IF ky$ = "C" THEN
	FOR b% = 0 TO 3
		max(b%) = 0
		min(b%) = &HFFFFFF
	NEXT b%
	END IF
	   FOR b% = 0 TO 3:  'auto PWM DETECT
		status(b%) = status(b%) AND &H21
'        IF status%(b%) = 1 THEN
'         pwm%(b%) = &H20
'         LOCATE 10 + b%, 65: PRINT "PWM XDCR"
'       'ELSE pwm%(b%) =
'END IF
		 OUT baseaddr% + 3 + b% * 4, 16 + pwm%(b%)
	   NEXT b%

	   'OUT baseaddr% + 3, 16
	   'OUT baseaddr% + 7, 16
	   'OUT baseaddr% + 11, 16
	   'OUT baseaddr% + 15, 16
	   FOR b% = 0 TO 3
		LOCATE 10 + b%, 10
		timeout = 0
		status%(b%) = 0
		WHILE status%(b%) = 0 AND timeout < 150
			status%(b%) = INP(baseaddr% + 3 + b% * 4)
			status%(b%) = status%(b%) AND &H80
			timeout = timeout + 1
		WEND
		IF timeout < 150 THEN
			posn(b%) = INP(baseaddr% + 2 + b% * 4)
			posn(b%) = posn(b%) * 256
			posn(b%) = posn(b%) + INP(baseaddr% + 1 + b% * 4)
			posn(b%) = posn(b%) * 256
			posn(b%) = posn(b%) + INP(baseaddr% + b% * 4)
			IF posn(b%) < min(b%) THEN
				min(b%) = posn(b%)
				ELSE
					IF posn(b%) > max(b%) THEN
					max(b%) = posn(b%)
					END IF
			END IF

			PRINT posn(b%), max(b%), min(b%), HEX$(INP(baseaddr% + 3 + b% * 4))
		ELSE
			
			status%(b%) = INP(baseaddr% + 3 + b% * 4)
			PRINT "TIMED OUT", , , HEX$(status%(b%))
		END IF
	   NEXT b%
	   WEND
progend:
END

